package com.archway.nearshop.zdemo.ademo.dao.interfaces;


import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.archway.nearshop.zdemo.ademo.domain.TestTable;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;

@Repository
public interface NewsTableMapper{
	
	/********select********/
	//根据id查询
	@Select(value="SELECT * FROM test_table WHERE id = #{id}")
	TestTable getById(int id);
	
	//查询所有
	@Select(value="SELECT * FROM test_table")
	@Results({
		@Result(id=true, column="id", property="id"),
		@Result(column="title", property="title"),
		@Result(column="content", property="content")
	})
	List<TestTable> getAll();
	
	//查询所有数量
	@Select(value="SELECT count(1) FROM test_table")
	int getAllCount();
	
	//带分页 查询
	@Select(value="SELECT * FROM test_table")
	@Results({
		@Result(id=true, column="id", property="id"),
		@Result(column="title", property="title"),
		@Result(column="content", property="content")
	})
	List<TestTable> getWithPaginator(PageBounds pageBounds);
	
	//带分页 查询
	@Select(value="SELECT count(1) FROM test_table")
	int getWithPaginatorCount(PageBounds pageBounds);
	
	
	/********insert*********/
	//插入所有值，包括自动生成的主键
	@Insert(value="INSERT INTO test_table(title,content) VALUES(#{title},#{content})")
	@Options(useGeneratedKeys=true, keyProperty="id") //自动生成主键
	int insert(TestTable table);//返回受影响行数，其中 TestTable table中可以拿到新的id
	//插入部分空值
	@Insert(value="INSERT INTO test_table(title) VALUES(#{title})")
	@Options(useGeneratedKeys=true, keyProperty="id") //自动生成主键
	int insertNull(TestTable table);//返回受影响行数，其中 TestTable table中可以拿到新的id
	
	
	/*********update*********/
	//更新数据
	@Update(value="UPDATE test_table SET title = #{title},content='某个定值' WHERE id >5")
	int update(TestTable table);
	

	/**********delete*********/
	//删除数据
	@Delete("DELETE FROM test_table WHERE id=#{id}")
	int deleteById(int id);
	
	
}
